$(document).ready(function() {
	mui.init();
	mui.plusReady(function() {
		plus.nativeUI.showWaiting("数据加载中...");
		var wx=plus.webview.currentWebview();
		//订单数据
		var signx = false;
		var refundPrice=0;
		function dmpay(type, result) {
			console.log(wx.authNo);
			var sum = $('#sum').val();
			require(weburl + model3, "json", "post", {
				"token": localStorage.getItem('token'),
				"out_trade_no":wx.orderNum,
				"auth_no":wx.authNo
			}, function(response) {
				plus.nativeUI.closeWaiting();
				console.log(wx.orderNum);
				//服务器返回响应
				if(response.status == 1) {
					if(response.data.pay_user == "支付宝") {
						$(".detail_logo img").attr("src", "../img/zhifubao.png");
					} else if(response.data.pay_user == "微信") {
						$(".detail_logo img").attr("src", "../img/weixin.png");
					}
					var datastr = response.data;
					$('.money').html('￥' + datastr.total_amount);
					//localStorage.setItem("refundPrice", datastr.total_amount);
					refundPrice=datastr.total_amount;
					$('.orderNum').html(datastr.out_trade_no);
					$('.time').html(datastr.created_at);
					$('.shopName').html(datastr.store_name);
					$('.phone').html(datastr.store_phone);
					$('.cashier').html(response.data.pay_user);
					$(".bz").html(response.data.remark);
					var numm = response.data.pay_status;
					var xx=$('.status').html(response.data.pay_status_txt); 
				} else {
					mui.toast('订单不存在', {
						duration: 'long',
						type: 'div'
					});
				}
				
				mui("body").on("tap", ".dayin", function() {
					Bluetooth(); 
					if(response && response.status == 1) {
						var str = response.data.print_body;
						var reg = /\\n/g;
						str = str.replace(reg, '\n');
						mui.closePopups();
						mui.confirm("打印小票？", " ", ["打印", "关闭"], function(e) {
							if(e.index == 0) {
								if(signx == false) {
									printTicket(response.data.print_array);
//									ticket(response.data.store_name, str, response.data.out_trade_no);
									signx = true;
									setTimeout(function() {
										signx = false;
									}, 3000);
								}
								return false;
							} else {

							}
						}, "div");
					} else {
						mui.alert("打印订单失败", " ", "关闭", function(e) {}, "div");
					}
				})
			}, function() {
				//异常处理；
				plus.nativeUI.closeWaiting();
				mui.toast('网络错误，请检查您的网络是否正确', {
					duration: 'long',
					type: 'div'
				});
			})
		}
		dmpay();
		
		//点击退款
		mui("body").on("tap", ".refund", function() {
			mui.openWindow({url:"../view/refund.html", id:"refund",extras:{
				orderNum:wx.orderNum,
				refundPrice:refundPrice
			}});
		})

		function payStatus(numb) {
			var sta = ""
			switch(numb) {
				case 1:
					sta = "支付成功";
					break;
				case 2:
					sta = "支付取消";
					break;
				case 3:
					sta = "等待支付";
					break;
				case 4:
					sta = "已退款";
					break;
				case 5:
					sta = "订单关闭";
					break;
			}
			return sta;
		}
	})

})